﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Mani.Common.Security;
using System.Web.Security;

namespace Mani.Common.UI.Controls
{
    public partial class ChangePassword : System.Web.UI.UserControl
    {
        public ISecurityManager securityManager { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (securityManager == null)
            {
                securityManager = new SecurityManager();
                securityManager.authProvider = new WebAuthorizationProvider();
            }
        }

        protected void btnSaveChanges_Click(object sender, EventArgs e)
        {
            bool result = securityManager.ChangePassword(txtOldPassword.Text, txtNewPassword.Text, Membership.ApplicationName);

            if (result)
            {
                UIHelper.ClientAlert(this.Page, "رمز عبور با موفقیت تغییر یافت");
                UIHelper.ClientRedirect(this.Page, "/Default.aspx");
            }
            else
                UIHelper.ClientAlert(this.Page, "تغییر با خطا مواجه شد لطفا مجددا تلاش کنید");
        }
    }
}